package com.eqdd.yiqidian.ui.tongxunlu.stafftree

import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.eqdd.yiqidian.R
import com.eqdd.yiqidian.bean.DepartmentStaffTreeBean
import com.eqdd.yiqidian.utils.ImageUtil
import com.jhj.datalibrary.tree.multi.SimpleMultiListAdapter
import kotlinx.android.synthetic.main.layout_multi_tree_node.view.*

/**
 *
 * Created by jhj on 17-9-8.
 */
class StaffTreeMultiListAdapter(val mContext: Context) : SimpleMultiListAdapter<DepartmentStaffTreeBean, StaffTreeMultiListAdapter.ItemViewHolder>() {



    var type = ""



    override fun onBindItemViewHolder(holder: ItemViewHolder, data: DepartmentStaffTreeBean, position: Int) {
        holder.itemView?.let {
            it.tv_name.text = data.name
            it.tv_id.text = data.department
            ImageUtil.setCircleImage(data.icon, it.iv_tree_mark)
            it.checkbox.isClickable = false
            if (data.isChecked) {
                it.checkbox.setImageResource(R.drawable.icon_choice)
            } else {
                it.checkbox.setImageResource(R.drawable.icon_choice_no)
            }
        }
    }

    override fun onCreateItemView(parent: ViewGroup?, viewType: Int): View {
        return LayoutInflater.from(parent?.context).inflate(R.layout.layout_multi_tree_node, parent, false)
    }

    override fun onCreateItemViewHolder(view: View): ItemViewHolder {
        return ItemViewHolder(view)
    }

    inner class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        init {
            itemView.setOnClickListener {
                val bean = itemView.tag as DepartmentStaffTreeBean
                itemViewOnClick(bean)
            }

        }

    }
}